package com.wanxi.controller;

import com.alibaba.fastjson2.JSONObject;
import com.wanxi.dto.ResultDTO;
import com.wanxi.service.ProductTypeService;
import com.wanxi.vo.ProductTypeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/productType")
@CrossOrigin(origins = "http://localhost:8081")
public class ProductTypeController {
    @Autowired
    ProductTypeService productTypeService;

    @PutMapping("/add")
    public String addProductType(ProductTypeVO productTypeVO){
        ResultDTO resultDTO = productTypeService.addProductType(productTypeVO);
        return JSONObject.toJSONString(resultDTO);
    }

    @DeleteMapping("/delete")
    public String deleteProductType(ProductTypeVO productTypeVO){
        ResultDTO resultDTO = productTypeService.deleteProductType(productTypeVO);
        return JSONObject.toJSONString(resultDTO);
    }

    @GetMapping("/findAll")
    public String findAllProductType(){
        ResultDTO allType = productTypeService.findAllType();
        return JSONObject.toJSONString(allType);
    }

    @PostMapping("/findById")
    public String findProductTypeById(ProductTypeVO productTypeVO){
        ResultDTO productTypeById = productTypeService.findProductTypeById(productTypeVO);
        return JSONObject.toJSONString(productTypeById);
    }

    @PostMapping("/updateEnable")
    public String updateProductTypeEnable(ProductTypeVO productTypeVO){
        ResultDTO resultDTO = productTypeService.updateEnable(productTypeVO);
        return JSONObject.toJSONString(resultDTO);
    }

    @PostMapping("/update")
    public String updateProductType(ProductTypeVO productTypeVO){
        ResultDTO resultDTO = productTypeService.updateProductType(productTypeVO);
        return JSONObject.toJSONString(resultDTO);
    }
}
